package com.yuyu.music.play.controller;

import com.yuyu.music.play.service.MusicPlayer;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class MusicPlayerController {

    private static final Logger log = LoggerFactory.getLogger(MusicPlayerController.class);

    @Autowired
    MusicPlayer musicPlayer;

    @GetMapping("/play")
    public ResponseEntity<String> playMusic(String name) throws Exception {
        log.info("play music : {}", name);
        musicPlayer.playMusic(name);
        return ResponseEntity.ok("playing music :" + name);
    }

    @GetMapping("/stop")
    public ResponseEntity<String> stopPlaying() {
        log.info("stop playing music");
        musicPlayer.stopMusic();
        return ResponseEntity.ok("stop playing music");
    }
}
